// pages/user-my-task/user-my-task.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgBase: app.globalData.imgUrl,
    localImg: app.globalData.staticimgUrl,
    userInfo: {},      // 用户信息
    paiming: "",       // 排名
    taskOther: [],     // 其他任务
    taskNew:[],        // 今日任务
    loginValue: '',    // 登入获取的值 
    sharePerson: '',   // 分享多少人
    shareValue: '',    // 分享值
    exampleValue: '',  // 写案例值
    shoppingValue: ''  // 购买值
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.TaskByUser();
  },
  // 获取用户美丽任务
  TaskByUser() {
    const that = this;
    const param = {
      userId: wx.getStorageSync('userid')
    };
    app.request({
      url: 'doctor/memberTaskApi/getMemberTaskByUser',
      data: param,
      success: function(res) {
        that.setData({
          userInfo: res.data.userInfo,
          taskOther: res.data.taskOther,
          taskNew: res.data.taskNew,
          currUser: res.data.currUser,
          paiming: res.data.currUser.rownum,
        })
        that.showText();
      },
      fail: function(res) {
        
      }
    });
  },
  // 显示任务的美丽币数值
  showText(){
    const taskNew = this.data.taskNew;
    const taskOther = this.data.taskOther;
    for (let i = 0; i<taskNew.length;i++){
      if(taskNew[i].taskName == '登录'){
        this.setData({
          loginValue: taskNew[i].rewardMoney
        })
      }
      if (taskNew[i].taskName == '分享'){
        this.setData({
          sharePerson: taskNew[i].remark,
          shareValue: taskNew[i].rewardMoney
        })
      }
    }
    for (let j = 0; j < taskOther.length; j++) {
      if (taskOther[j].taskName == '写案例') {
        this.setData({
          exampleValue: taskOther[j].rewardMoney
        })
      }
      if (taskOther[j].taskName == '消费') {
        this.setData({
          shoppingValue: taskOther[j].rewardMoney
        })
      }
    }
  },

  //跳转购物，案例
  toFinish(e){
    const type = e.currentTarget.dataset.type;
    type == 1 &&
    wx.navigateTo({
      url: '../doctor-my-case/doctor-my-case?isShowAdd='+1
    });
    
    type == 2 &&
    wx.navigateTo({
      url: '../user-shop-goods/user-shop-goods'
    });
  }
})